function loadLayer(link) {
	var oldDiv;
	if ( oldDiv = document.getElementById("upper")) {
		document.getElementsByTagName("body")[0].removeChild(oldDiv);
	}
	var xmlhttp;
	$("body").css('overflow', 'hidden');
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'upper');
	document.getElementsByTagName("body")[0].appendChild(newdiv);
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById("upper").innerHTML = xmlhttp.responseText;
		}
	};
	xmlhttp.open("GET", link, true);
	xmlhttp.send();
}

function closeLayer() {
	var oldDiv;
	if ( oldDiv = document.getElementById("upper")) {
		document.getElementsByTagName("body")[0].removeChild(oldDiv);
	}
	$("body").css('overflow', 'auto');
}

function addUser(link) {
	var username = $("#txtUsername").val();
	var pswd = $("#txtPassword").val();
	var fname = $("#txtFirstname").val();
	var lname = $("#txtLastname").val();
	var email = $("#txtEmail").val();
	var phone = $("#txtPhone").val();
	var fax = $("#txtFax").val();
	var add = $("#txtAdd").val();
	var add2 = $("#txtAdd2").val();
	var city = $("#txtCity").val();
	var birthday = $("#txtBirthday").val();
	var isUser = $("#chkUser").is(":checked");
	var datastring = "txtUsername=" + username + "&txtPassword=" + pswd + "&txtFirstname=" + fname + "&txtLastname=" + lname + "&txtEmail=" + email + "&txtPhone=" + phone + "&txtFax=" + fax + "&txtAdd=" + add + "&txtAdd2=" + add2 + "&txtCity=" + city + "&txtBirthday=" + birthday + "&submit=1";
	if (isUser) {
		datastring = datastring + "&chkUser=1";
	}
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if (xmlhttp.responseText == 'OK') {
				closeLayer();
				location.reload();
			}
		}
	}
	xmlhttp.open("POST", link, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(datastring);

	return false;
}

function editUser(link) {
	var id = $('#txtId').val();
	var username = $("#txtUsername").val();
	var pswd = $("#txtPassword").val();
	var fname = $("#txtFirstname").val();
	var lname = $("#txtLastname").val();
	var email = $("#txtEmail").val();
	var phone = $("#txtPhone").val();
	var fax = $("#txtFax").val();
	var add = $("#txtAdd").val();
	var add2 = $("#txtAdd2").val();
	var city = $("#txtCity").val();
	var birthday = $("#txtBirthday").val();
	var isUser = $("#chkUser").is(":checked");
	var datastring = "txtId=" + id + "&txtUsername=" + username + "&txtPassword=" + pswd + "&txtFirstname=" + fname + "&txtLastname=" + lname + "&txtEmail=" + email + "&txtPhone=" + phone + "&txtFax=" + fax + "&txtAdd=" + add + "&txtAdd2=" + add2 + "&txtCity=" + city + "&txtBirthday=" + birthday + "&submit=1";
	if (isUser) {
		datastring = datastring + "&chkUser=1";
	}
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if (xmlhttp.responseText == 'OK') {
				closeLayer();
				location.reload();
			}
		}
	}
	xmlhttp.open("POST", link, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(datastring);
	return false;
}

function selectAll(obj, objname) {
	var chkObj = $('[name="' + objname + '"]')
	var length = chkObj.length;
	if ($(obj).is(":checked")) {
		chkObj.attr('checked', 'checked');
	} else {
		chkObj.removeAttr('checked');
	}
}

function customSubmit(formId, action) {
	var form = $('#' + formId);
	form.attr('action', action);
	form.submit();
}

